/*
Multi-part script for use with IBrowse and Yam (Miami).
Arguments:
,reads newmail.
ALL ,reads ALL mail.
ALTER ,reads newmail and alters the status to old in yam.
CHECK ,checks for mail using miami, disconnects.
SEND , as CHECK but also sends your outgoing mail.
OTHER ,reads any of yams folders
DEBUG ,if the IBrowsepart fails.. pinpoints mailfile.
*/
OPTIONS RESULTS
OPTIONS FAILAT 21
call addlib('libs:rexxreqtools.library',0,-30)
NL= '0a'x /* newline */
folder=0
temppath='RAM:T/Newmail'
title= 'Newmail by sorenf@hem1.passagen.se 1998'
what_but= '_IBrowse|_Yam|Cancel'
tags= 'rt_pubscrname=IBROWSESCREEN' /* Change here the name of the screen IBROWSE runs */
where_txt='There is mail for You! Select viewer.'
preset=0
ARG mode
IF mode='ALTER' THEN DO ; mode='' ; alt='YES' ; END
IF POS('OTHER',mode)~=0 THEN DO
len=LENGTH(mode)
IF len>5 THEN folder=DELSTR(mode,1,5)
mode='OTHER'
END
IF ~SHOW('Ports','YAM') THEN CALL START "YAM","HIDE"
IF mode='CHECK' | mode='SEND' THEN DO
ADDRESS 'COMMAND' 'SETENV NOICQ'
ADDRESS 'YAM' 'mailcheck'; res=RESULT
IF res='0 0 0 0' THEN DO
IF ~SHOW('Ports','MIAMI.1') THEN CALL START "Miami","DONTCONNECT HIDE SETTINGS miami:miami.default"
IF SHOW('Ports','MIAMI.1') & SHOW('Ports','YAM') THEN DO
ADDRESS 'MIAMI.1' 'ONLINE'
IF mode='SEND' THEN ADDRESS 'YAM' 'mailsendall'
good=RESULT
ADDRESS 'YAM' 'mailcheck'; res=result
ADDRESS 'MIAMI.1' 'OFFLINE'
ADDRESS 'COMMAND' 'WAIT 10'
ADDRESS 'MIAMI.1' 'QUIT'
END
END
ADDRESS 'COMMAND' 'UNSETENV NOICQ'
IF res=-1 | good=-1 THEN SAY 'Somethingwentwrong'
IF res<1 THEN rtezrequest('Sorry ! No mail.',':(',title,'rtez_defaultresponse=1')
EXIT
END
IF mode='' THEN DO
sel=rtezrequest(where_txt,what_but,title,'rtez_defaultresponse=1')
IF sel=0 then Exit
IF sel=2 then do; CALL SHOWYAM ; SETFOLDER 0; EXIT; END
IF EXISTS('sys:c/play16') & EXISTS('Ibrowse:rexx/IBS_Images/mailsound.wav') THEN DO
ADDRESS 'COMMAND' 'Run >NIL: play16 >NIL: Ibrowse:rexx/IBS_Images/mailsound.wav'; END
END
IF mode='OTHER' & folder=0 THEN DO
oldname='';list=''
ADDRESS 'YAM'
DO i=0 TO 12
'SETFOLDER' i
'GETFOLDERINFO' 'NAME'; name=RESULT
IF name=oldname THEN BREAK
say i||' '||NAME
oldname=name
list=list||i||' '||name||NL
END
long = rtgetlong(preset,list, "Enter a number:", , "rtgl_min = 0 rtgl_max = "i-1,'2')
if rtresult ~=0 then folder=long
if rtresult =0 then EXIT
END
/* ************** Here starts the IBrowse-display part ************ */
IF ~SHOW('Ports','IBROWSE') THEN CALL START "IBROWSE",""
IF SHOW('Ports','IBROWSE') & SHOW('Ports','YAM') THEN DO
NLNL= '0a0a'x /* 2 newlines */
imgpath='="file://localhost/IBrowse:Rexx/IBS_Images/'
fileinc= ' '
repl= '
'
new= '
'
fresh= '
'
repl= '
'
old= '
'
more= '
'
head= '
' epre= '' ibserror= 'Newmail failed to decode this message correctly, please view with yam!
' IF mode='ALL' THEN mode_txt=' Here is your mail.' IF mode='DEBUG' THEN mode_txt=' DEBUGED' ADDRESS 'COMMAND' 'makedir >NIL: ' temppath ADDRESS 'YAM' 'SetFolder' folder GetFolderinfo MAX; max=RESULT 'GETFOLDERINFO' 'NAME'; name=RESULT IF mode='OTHER' THEN mode_txt=name||':' linkpage=head||''||mode_txt||''||NL DO a=0 TO max-1 setmail a getmailinfo STA; status=result IF status='U' | status="N" | mode~='' THEN DO err=0 /* Get info from yam */ getmailinfo FRO ; from=result getmailinfo SUB ; subject=LEFT(result,30) getmailinfo FIL ; file=result IF mode='DEBUG' THEN say 'checking file: '||file /* use email as name if name is missing */ namepos=pos('<',from) IF namepos=0 THEN Do from=from||' <'||from ;namepos=pos('<',from) END /* split name and email-address */ name=LEFT(from,namepos-1) ;name=STRIP(name,'B','" ') ;name=LEFT(name,30) email=DELSTR(from,1,namepos); email=STRIP(email,'T','>') titel='From: '||name||'Subject: '||subject mailto=''||email||''||NL /* Read mailfile */ open(inputfile,file,'R') out=readch(inputfile,65000) close(inputfile) bin=0 gem=0 html=0 list='' content=0 boundary='' post=pos(NLNL,out) mailinfo=LEFT(out,post) out=DELSTR(out,1,post) bonpos=pos('boundary',mailinfo) /* set some stuff upp if multipart MIME */ IF bonpos~=0 THEN DO line=SUBSTR(mailinfo,bonpos,pos(NL,mailinfo,bonpos)-bonpos) boundary=SUBSTR(line,11,24) appex=bonpos oldposb=0 DO FOREVER appex=pos(boundary,out,oldposb+1) IF appex~=0 THEN DO posb=pos(NLNL,out,appex) nextline=substr(out,appex,posb-appex) IF pos('text/plain',nextline)~=0 THEN DO gem=gem+1 IF gem=1 THEN DO CALL QUOTECUT END END IF pos('text/html',nextline)~=0 THEN DO html=html+1 IF html=1 THEN DO content=0 CALL QUOTECUT END END IF pos('application/octet-stream',nextline)~=0 THEN bin=bin+1 END oldposb=posb IF appex=0 THEN BREAK END endpos=pos(boundary,out) IF endpos~=0 THEN DO endpos=lastpos(NL,out,endpos) out=LEFT(out,endpos) END IF endpos=0 THEN out=ibserror || out END /* Alters the status of unread-mails to old if selected */ IF alt='YES' THEN ADDRESS 'COMMAND' 'Filenote' file 'O' filepos=LASTPOS('/',file) file=DELSTR(file,1,filepos) /* adding Icons */ if status='N' then icon=fresh if status='U' then icon=new if status='R' then icon=repl if status='O' then icon=old if bin>0 then icon=icon || fileinc if gem>1 THEN icon=icon || more /* Find end of text if not MIME multipart */ IF bonpos=0 THEN DO endpos=pos('UUDECODE',out) IF endpos~=0 THEN DO endpos=pos(NLNL,out,endpos) out=LEFT(out,endpos) icon=icon || more END END IF content=1 THEN DO /* fixing some swedish characters */ CALL MIME "=F6","246" ; CALL MIME "=E5","229" ; CALL MIME "=E4","228" CALL MIME "=D6","214" ; CALL MIME "=C5","197" ; CALL MIME "=C4","196" /* removing some crap */ CALL MIME '=20'||NL,"10"; CALL MIME "="||NL,"" IF html~=0 THEN out=epre||out END linkpage=linkpage||''||titel||''||icon||NL out=pre||titel||icon||NL||'Mail to: '||mailto||out IF html=0 THEN out =body||out||epre out='' open('outputfile',temppath'/newmail.html','W') line=writeln('outputfile',linkpage) close('outputfile') ADDRESS 'IBROWSE' GOTOURL URL 'file://localhost/'temppath'/newmail.html' SCREENTOFRONT END EXIT MIME: arg mime,char len=LENGTH(mime) DO WHILE pos(mime,out)~=0 mimechar=pos(mime,out) out=DELSTR(out,mimechar,len) IF char~="" THEN out=INSERT(D2C(char),out,mimechar-1) END RETURN START: arg program,option ADDRESS 'COMMAND' 'RUN >NIL: 'program':'program' 'option 'sys:rexxc/waitforport' program RETURN QUOTECUT: IF pos('quoted-printable',nextline)~=0 THEN content=1 out=DELSTR(out,1,posb) posb=0 RETURN SHOWYAM: ADDRESS 'YAM' 'INFO VERSION' yver=WORD(RESULT,3) IF yver>=2 THEN ADDRESS 'COMMAND' 'YAM:YAM' ADDRESS 'YAM' 'SHOW' RETURN'||name||' '||out /* save mailfile */ open('outputfile',temppath'/'file'.html','W') line=writeln('outputfile',out) close('outputfile') IF mode='DEBUG' THEN say 'processed file 'file' OK!' END END IF alt='YES' THEN ADDRESS 'YAM' 'MAILUPDATE' /* Save indexfile */ linkpage=linkpage||'